package pl.edu.agh.neural.simple;

import pl.edu.agh.neural.core.ILayer;
import pl.edu.agh.neural.core.INeuron;
import pl.edu.agh.neural.simple.activation.ConstantActivation;

import java.util.ArrayList;
import java.util.List;

public class SimpleLayer implements ILayer {

	protected List<SimpleNeuron> neurons;

    public SimpleLayer(List<? extends SimpleNeuron> neurons, boolean hasBias) {
        this.neurons = new ArrayList<>(neurons);
        if (hasBias) {
            SimpleNeuron biasNeuron = new SimpleNeuron(new ConstantActivation(), new InputConnection[0]);
            this.neurons.add(biasNeuron);
        }
    }

    @Override
    public List<? extends INeuron> getNeurons() {
        return neurons;
    }

    @Override
    public double[] evaluate() {
        double[] result = new double[neurons.size()];
        for (int i = 0; i < result.length; i++) {
            result[i] = neurons.get(i).evaluate();
        }

        return result;
    }
}
